package edu.njust.cma.service.impl;

import edu.njust.cma.DTO.*;
import edu.njust.cma.config.ConstantConfig;
import edu.njust.cma.config.TimeConfig;
import edu.njust.cma.mapper.*;
import edu.njust.cma.pojo.*;
import edu.njust.cma.service.LabStaffService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;

@Service
public class LabStaffServiceImpl implements LabStaffService {
    @Override
    public List<SubTaskForLab> getSubTaskForStaff(int userId) {
        List<SubTaskForLab> subTaskForLabs = new ArrayList<>();
        List<SubtaskStaff> subTaskForStaff = subtaskStaffMapper.getStaffTaskByUserId(userId);

        // 去重 user_id相同 task_id相同的只保留一个
        for (int i = 0; i < subTaskForStaff.size(); i++) {
            for (int j = i + 1; j < subTaskForStaff.size(); j++) {
                if (subTaskForStaff.get(i).getTaskId()==subTaskForStaff.get(j).getTaskId()) {
                    subTaskForStaff.remove(j);
                    j--;
                }
            }
        }
        for (SubtaskStaff subtaskStaff : subTaskForStaff) {
                Task task = taskMapper.getTaskById(subtaskStaff.getTaskId());
                SmallProject smallProject = smallProjectMapper.getSmallProjectById(task.getSmallProjectId());
                Project project = projectMapper.getProjectById(smallProject.getProjectId());
                Standard standard = standardMapper.getStandardById(smallProject.getStandardId());
                User labUser = userMapper.getUserById(project.getLabDirectorId());
                // 找到这个任务的最后一次提交
                Submission submission = submissionmapper.
                        getSubmissionLastBySubtaskIdAndType(subtaskStaff.getId(), ConstantConfig.STAFF_SubTASK);
                SubTaskForLab subTaskForLab = new SubTaskForLab(
                        project.getId(),
                        task.getId(),
                        project.getName(),
                        standard.getName(),
                        task.getName(),
                        labUser,
                        ConstantConfig.STAFF_SubTASK,
                        task.getCreationTime(),
                        subtaskStaff.getStatus(),
                        submission
                );
                subTaskForLabs.add(subTaskForLab);
        }
        return subTaskForLabs;
    }

    @Override
    public List<SubTaskForLab> getSubTaskForFacility(int userId) {
        List<SubTaskForLab> subTaskForLabs = new ArrayList<>();
        List<SubtaskEquipment> subTaskForEquipment = subtaskFacilityComparisonInspectMapper.getFacilityTaskByUserIdAndType
                (userId,ConstantConfig.FACILITIES);
        for (SubtaskEquipment subtaskEquipment : subTaskForEquipment) {
            Task task = taskMapper.getTaskById(subtaskEquipment.getTaskId());
            SmallProject smallProject = smallProjectMapper.getSmallProjectById(task.getSmallProjectId());
            Project project = projectMapper.getProjectById(smallProject.getProjectId());
            Standard standard = standardMapper.getStandardById(smallProject.getStandardId());
            User labUser = userMapper.getUserById(project.getLabDirectorId());
            // 找到这个任务的最后一次提交
            Submission submission = submissionmapper.
                    getSubmissionLastBySubtaskIdAndType(subtaskEquipment.getId(), ConstantConfig.FACILITY_SubTASK);
            SubTaskForLab subTaskForLab = new SubTaskForLab(
                    project.getId(),
                    task.getId(),
                    project.getName(),
                    standard.getName(),
                    task.getName(),
                    labUser,
                    ConstantConfig.FACILITY_SubTASK,
                    task.getCreationTime(),
                    subtaskEquipment.getStatus(),
                    submission
            );
            subTaskForLabs.add(subTaskForLab);
        }
        return subTaskForLabs;
    }

    @Override
    public List<SubTaskForLab> getSubTaskForCompare(int userId) {
        List<SubTaskForLab> subTaskForLabs = new ArrayList<>();
        List<SubtaskEquipment> subTaskForEquipment = subtaskFacilityComparisonInspectMapper.getFacilityTaskByUserIdAndType
                (userId,ConstantConfig.COMPARISON);
        for (SubtaskEquipment subtaskEquipment : subTaskForEquipment) {
            Task task = taskMapper.getTaskById(subtaskEquipment.getTaskId());
            SmallProject smallProject = smallProjectMapper.getSmallProjectById(task.getSmallProjectId());
            Project project = projectMapper.getProjectById(smallProject.getProjectId());
            Standard standard = standardMapper.getStandardById(smallProject.getStandardId());
            User labUser = userMapper.getUserById(project.getLabDirectorId());
            // 找到这个任务的最后一次提交
            Submission submission = submissionmapper.
                    getSubmissionLastBySubtaskIdAndType(subtaskEquipment.getId(), ConstantConfig.COMPARISON_SubTASK);
            SubTaskForLab subTaskForLab = new SubTaskForLab(
                    project.getId(),
                    task.getId(),
                    project.getName(),
                    standard.getName(),
                    task.getName(),
                    labUser,
                    ConstantConfig.COMPARISON_SubTASK,
                    task.getCreationTime(),
                    subtaskEquipment.getStatus(),
                    submission
            );
            subTaskForLabs.add(subTaskForLab);
        }
        return subTaskForLabs;
    }

    @Override
    public List<SubTaskForLab> getSubTaskForInspect(int userId) {
        List<SubTaskForLab> subTaskForLabs = new ArrayList<>();
        List<SubtaskEquipment> subTaskForEquipment = subtaskFacilityComparisonInspectMapper.getFacilityTaskByUserIdAndType
                (userId,ConstantConfig.INSPECT);
        for (SubtaskEquipment subtaskEquipment : subTaskForEquipment) {
            Task task = taskMapper.getTaskById(subtaskEquipment.getTaskId());
            SmallProject smallProject = smallProjectMapper.getSmallProjectById(task.getSmallProjectId());
            Project project = projectMapper.getProjectById(smallProject.getProjectId());
            Standard standard = standardMapper.getStandardById(smallProject.getStandardId());
            User labUser = userMapper.getUserById(project.getLabDirectorId());
            // 找到这个任务的最后一次提交
            Submission submission = submissionmapper.
                    getSubmissionLastBySubtaskIdAndType(subtaskEquipment.getId(), ConstantConfig.INSPECT_SubTASK);
            SubTaskForLab subTaskForLab = new SubTaskForLab(
                    project.getId(),
                    task.getId(),
                    project.getName(),
                    standard.getName(),
                    task.getName(),
                    labUser,
                    ConstantConfig.INSPECT_SubTASK,
                    task.getCreationTime(),
                    subtaskEquipment.getStatus(),
                    submission
            );
            subTaskForLabs.add(subTaskForLab);
        }
        return subTaskForLabs;
    }

    @Override
    public List<SubTaskForLab> getSubTaskForSample(int userId) {
        List<SubTaskForLab> subTaskForLabs = new ArrayList<>();
        List<SubtaskSample> subTaskForSample = subtaskSampleMapper.getSampleTaskByUserId(userId);
        for (SubtaskSample subtaskSample : subTaskForSample) {
            Task task = taskMapper.getTaskById(subtaskSample.getTaskId());
            SmallProject smallProject = smallProjectMapper.getSmallProjectById(task.getSmallProjectId());
            Project project = projectMapper.getProjectById(smallProject.getProjectId());
            Standard standard = standardMapper.getStandardById(smallProject.getStandardId());
            User labUser = userMapper.getUserById(project.getLabDirectorId());
            // 找到这个任务的最后一次提交
            Submission submission = submissionmapper.
                    getSubmissionLastBySubtaskIdAndType(subtaskSample.getId(), ConstantConfig.SAMPLE_SubTASK);
            SubTaskForLab subTaskForLab = new SubTaskForLab(
                    project.getId(),
                    task.getId(),
                    project.getName(),
                    standard.getName(),
                    task.getName(),
                    labUser,
                    ConstantConfig.SAMPLE_SubTASK,
                    task.getCreationTime(),
                    subtaskSample.getStatus(),
                    submission
            );
            subTaskForLabs.add(subTaskForLab);
        }
        return subTaskForLabs;
    }

    @Override
    public List<SubTaskForLab> getSubTaskForSimulate(int userId) {
        List<SubTaskForLab> subTaskForLabs = new ArrayList<>();
        List<SubtaskSimulation> subTaskForSimulation = subTaskSimulationMapper.getSimulationTaskByUserId(userId);
        for (SubtaskSimulation subtaskSimulation : subTaskForSimulation) {
            Task task = taskMapper.getTaskById(subtaskSimulation.getTaskId());
            SmallProject smallProject = smallProjectMapper.getSmallProjectById(task.getSmallProjectId());
            Project project = projectMapper.getProjectById(smallProject.getProjectId());
            Standard standard = standardMapper.getStandardById(smallProject.getStandardId());
            User labUser = userMapper.getUserById(project.getLabDirectorId());
            // 找到这个任务的最后一次提交
            Submission submission = submissionmapper.
                    getSubmissionLastBySubtaskIdAndType(subtaskSimulation.getId(), ConstantConfig.SIMULATION_SubTASK);
            SubTaskForLab subTaskForLab = new SubTaskForLab(
                    project.getId(),
                    task.getId(),
                    project.getName(),
                    standard.getName(),
                    task.getName(),
                    labUser,
                    ConstantConfig.SIMULATION_SubTASK,
                    task.getCreationTime(),
                    subtaskSimulation.getStatus(),
                    submission
            );
            subTaskForLabs.add(subTaskForLab);
        }
        return subTaskForLabs;
    }

    @Override
    public List<SubTaskForLab> getSubTaskForExtra(int userId) {
        List<SubTaskForLab> subTaskForLabs = new ArrayList<>();
        List<SubtaskAdditionalRequirement> subTaskForExtra = subtaskAdditionalRequirementMapper.getSubtaskAdditionalRequirementByUserId(userId);
        for (SubtaskAdditionalRequirement subtaskAdditionalRequirement : subTaskForExtra) {
            Task task = taskMapper.getTaskById(subtaskAdditionalRequirement.getTaskId());
            SmallProject smallProject = smallProjectMapper.getSmallProjectById(task.getSmallProjectId());
            Project project = projectMapper.getProjectById(smallProject.getProjectId());
            Standard standard = standardMapper.getStandardById(smallProject.getStandardId());
            User labUser = userMapper.getUserById(project.getLabDirectorId());
            // 找到这个任务的最后一次提交
            Submission submission = submissionmapper.
                    getSubmissionLastBySubtaskIdAndType(subtaskAdditionalRequirement.getId(), ConstantConfig.ADDITIONAL_SubTASK);
            SubTaskForLab subTaskForLab = new SubTaskForLab(
                    project.getId(),
                    task.getId(),
                    project.getName(),
                    standard.getName(),
                    task.getName(),
                    labUser,
                    ConstantConfig.ADDITIONAL_SubTASK,
                    task.getCreationTime(),
                    subtaskAdditionalRequirement.getStatus(),
                    submission,
                    subtaskAdditionalRequirement.getId()
            );
            subTaskForLabs.add(subTaskForLab);
        }
        return subTaskForLabs;
    }

    @Override
    public List<SubTaskForLab> getAllSubTaskForLab(int userId) {
        List<SubTaskForLab> subTaskForLabs = new ArrayList<>();
        List<SubTaskForLab> subTaskForStaff = getSubTaskForStaff(userId);
        List<SubTaskForLab> subTaskForFacility = getSubTaskForFacility(userId);
        List<SubTaskForLab> subTaskForCompare = getSubTaskForCompare(userId);
        List<SubTaskForLab> subTaskForInspect = getSubTaskForInspect(userId);
        List<SubTaskForLab> subTaskForSample = getSubTaskForSample(userId);
        List<SubTaskForLab> subTaskForSimulate = getSubTaskForSimulate(userId);
        List<SubTaskForLab> subTaskForExtra = getSubTaskForExtra(userId);
        // 合并
        subTaskForLabs.addAll(subTaskForStaff);
        subTaskForLabs.addAll(subTaskForFacility);
        subTaskForLabs.addAll(subTaskForCompare);
        subTaskForLabs.addAll(subTaskForInspect);
        subTaskForLabs.addAll(subTaskForSample);
        subTaskForLabs.addAll(subTaskForSimulate);
        subTaskForLabs.addAll(subTaskForExtra);
        return subTaskForLabs;
    }
    @Override
    public List<SubTaskForLab> getUnSubmittedTask(int userId) {
        /**
         * 依次提取7种任务SubTaskForLab合并
         * 删除不满足条件的选项
         * 未提交的任务是：status=ConfigConstant.UNFINISHED && (submission==null || submission.status=4)
         * */

        List<SubTaskForLab> subTaskForLabs = getAllSubTaskForLab(userId);

        // 删除不满足条件的选项
        for (int i = 0; i < subTaskForLabs.size(); i++) {
            if(subTaskForLabs.get(i).getStatus() == ConstantConfig.FINISHED){
                subTaskForLabs.remove(i);
                i--;
                continue;
            }
            if (subTaskForLabs.get(i).getSubmission() != null) {
                if (subTaskForLabs.get(i).getSubmission().getReviewStatus() != ConstantConfig.DROP) {
                    subTaskForLabs.remove(i);
                    i--;
                }
            }
        }

        // 利用实体类的接口排序后返回
        subTaskForLabs.sort((o1, o2) -> {
            if (o1.getProjectId() > o2.getProjectId()) {
                return 1;
            } else if (o1.getProjectId() < o2.getProjectId()) {
                return -1;
            } else {
                if (o1.getTaskId() > o2.getTaskId()) {
                    return 1;
                } else if (o1.getTaskId() < o2.getTaskId()) {
                    return -1;
                } else {
                    return 0;
                }
            }
        });
        return subTaskForLabs;
    }

    @Override
    public List<SubTaskForLab> getUnReviewedTask(int userId) {
        /**
         * 依次提取7种任务SubTaskForLab合并
         * 删除不满足条件的选项
         * 未提交的任务是：status=ConfigConstant.UNFINISHED && (submission!=null && submission.status==ConfigConstant.WAIT )
         * */
        List<SubTaskForLab> subTaskForLabs = getAllSubTaskForLab(userId);
        // 删除不满足条件的选项
        for (int i = 0; i < subTaskForLabs.size(); i++) {
            if(subTaskForLabs.get(i).getStatus() == ConstantConfig.FINISHED){
                subTaskForLabs.remove(i);
                i--;
                continue;
            }
            if (subTaskForLabs.get(i).getSubmission() != null) {
                if (subTaskForLabs.get(i).getSubmission().getReviewStatus() != ConstantConfig.WAITING) {
                    subTaskForLabs.remove(i);
                    i--;
                }
            }
        }

        // 利用实体类的接口排序后返回
        subTaskForLabs.sort((o1, o2) -> {
            if (o1.getProjectId() > o2.getProjectId()) {
                return 1;
            } else if (o1.getProjectId() < o2.getProjectId()) {
                return -1;
            } else {
                if (o1.getTaskId() > o2.getTaskId()) {
                    return 1;
                } else if (o1.getTaskId() < o2.getTaskId()) {
                    return -1;
                } else {
                    return 0;
                }
            }
        });
        return subTaskForLabs;
    }
    @Override
    public List<SubTaskForLab> getUnCheckedTask(int userId) {
        List<SubTaskForLab> subTaskForLabList = getAllSubTaskForLab(userId);
        for(int i=0;i<subTaskForLabList.size();i++){
            SubTaskForLab subTaskForLab = subTaskForLabList.get(i);
            if(subTaskForLab.getStatus() == ConstantConfig.FINISHED){
                subTaskForLabList.remove(i);
                i--;
                continue;
            }
            if(subTaskForLab.getSubmission() == null || subTaskForLab.getSubmission().getReviewStatus() != ConstantConfig.NOT_PASS){
                subTaskForLabList.remove(i);
                i--;
            }
        }
        return subTaskForLabList;
    }

    @Override
    public List<SubTaskForLab> getFinishSubTaskForLab(int userId) {
        List<SubTaskForLab> subTaskForLabs = getAllSubTaskForLab(userId);
        for (int i = 0; i < subTaskForLabs.size(); i++) {
            if(subTaskForLabs.get(i).getStatus() != ConstantConfig.FINISHED){
                subTaskForLabs.remove(i);
                i--;
            }
        }
        return subTaskForLabs;
    }

    @Override
    public void submitForStaff(SubmitForStaff submitForStaff) {

        // 1.新建一个submission
        Submission submission = new Submission();
        submission.setTaskId(submitForStaff.getTaskId());
        submission.setReviewStatus(ConstantConfig.WAITING);
        String nowTime = TimeConfig.getNowTime();
        submission.setSubmissionTime(nowTime);
        submission.setType(ConstantConfig.STAFF_SubTASK);
        submissionmapper.create(submission);

        // 2.更新所有的subtask_staff的url和submission_time
        for(int i=0;i<submitForStaff.getAssessmentPdfUrls().size();i++){
            Integer staffId = submitForStaff.getStaffIds().get(i);

            SubtaskStaff subtaskStaff = subtaskStaffMapper.getSubtaskStaffByTaskIdAndStaffId
                    (submitForStaff.getTaskId(),staffId);

            subtaskStaff.setAssessmentPdfUrl(submitForStaff.getAssessmentPdfUrls().get(i));
            subtaskStaff.setTrainingPdfUrl(submitForStaff.getTrainingPdfUrls().get(i));
            subtaskStaff.setResumePdfUrl(submitForStaff.getResumePdfUrls().get(i));
            subtaskStaff.setAuthorizationPdfUrl(submitForStaff.getAuthorizationPdfUrls().get(i));
            subtaskStaff.setSubmissionTime(nowTime);

            subtaskStaffMapper.updateUrlAndTime(subtaskStaff);
        }

    }

    @Override
    public void submitForStaffAgain(SubmitForStaff submitForStaff) {
        // 将以前的Sumission的reviewStatus改为4
        submissionmapper.updateStatusWaitByTaskIdAndType(submitForStaff.getTaskId(),ConstantConfig.STAFF_SubTASK,ConstantConfig.DROP);
        submitForStaff(submitForStaff);
    }

    @Override
    public void submitForFacilities(SubmitForFacilities submitForFacilities) {

            // 1.新建一个submission
            Submission submission = new Submission();
            submission.setTaskId(submitForFacilities.getTaskId());
            SubtaskFacilityComparisonInspect subtaskFacility = subtaskFacilityComparisonInspectMapper.getSubtaskByTaskIdAndType(submitForFacilities.getTaskId(),ConstantConfig.FACILITIES);
            submission.setSubtaskId(subtaskFacility.getId());
            submission.setReviewStatus(ConstantConfig.WAITING);
            String nowTime = TimeConfig.getNowTime();
            submission.setSubmissionTime(nowTime);
            submission.setType(ConstantConfig.FACILITY_SubTASK);
            submissionmapper.create(submission);
            // 更新subTaskFacilityComparisonInspect的url和submission_time
            subtaskFacilityComparisonInspectMapper.updateUrlById(subtaskFacility.getId(),submitForFacilities.getCertificationPdfUrl());
            subtaskFacilityComparisonInspectMapper.updateTimeById(subtaskFacility.getId(),TimeConfig.getNowTime());
    }

    @Override
    public void submitForFacilitiesAgain(SubmitForFacilities submitForFacilities) {
        // 更新最后一次提交
        submissionmapper.updateStatusWaitByTaskIdAndType(submitForFacilities.getTaskId(),ConstantConfig.FACILITY_SubTASK,ConstantConfig.DROP);
        submitForFacilities(submitForFacilities);
    }

    @Override
    public void submitForCompare(SubmitForFacilities submitForFacilities) {
        // 1.新建一个submission
        Submission submission = new Submission();
        submission.setTaskId(submitForFacilities.getTaskId());
        SubtaskFacilityComparisonInspect subtaskFacility =
                subtaskFacilityComparisonInspectMapper.getSubtaskByTaskIdAndType(submitForFacilities.getTaskId(),ConstantConfig.COMPARISON);
        submission.setSubtaskId(subtaskFacility.getId());
        submission.setReviewStatus(ConstantConfig.WAITING);
        String nowTime = TimeConfig.getNowTime();
        submission.setSubmissionTime(nowTime);
        submission.setType(ConstantConfig.COMPARISON_SubTASK);
        submissionmapper.create(submission);
        // 更新subTaskFacilityComparisonInspect的url和submission_time
        subtaskFacilityComparisonInspectMapper.updateUrlById(subtaskFacility.getId(),submitForFacilities.getCertificationPdfUrl());
        subtaskFacilityComparisonInspectMapper.updateTimeById(subtaskFacility.getId(),TimeConfig.getNowTime());
    }

    @Override
    public void submitForCompareAgain(SubmitForFacilities submitForFacilities) {
        // 更新最后一次提交
        submissionmapper.updateStatusWaitByTaskIdAndType(submitForFacilities.getTaskId(),ConstantConfig.COMPARISON_SubTASK,ConstantConfig.DROP);
        submitForCompare(submitForFacilities);
    }

    @Override
    public void submitForInspect(SubmitForFacilities submitForFacilities) {
        // 1.新建一个submission
        Submission submission = new Submission();
        submission.setTaskId(submitForFacilities.getTaskId());
        SubtaskFacilityComparisonInspect subtaskFacility =
                subtaskFacilityComparisonInspectMapper.getSubtaskByTaskIdAndType(submitForFacilities.getTaskId(),ConstantConfig.INSPECT);
        submission.setSubtaskId(subtaskFacility.getId());
        submission.setReviewStatus(ConstantConfig.WAITING);
        String nowTime = TimeConfig.getNowTime();
        submission.setSubmissionTime(nowTime);
        submission.setType(ConstantConfig.INSPECT_SubTASK);
        submissionmapper.create(submission);
        // 更新subTaskFacilityComparisonInspect的url和submission_time
        subtaskFacilityComparisonInspectMapper.updateUrlById(subtaskFacility.getId(),submitForFacilities.getCertificationPdfUrl());
        subtaskFacilityComparisonInspectMapper.updateTimeById(subtaskFacility.getId(),TimeConfig.getNowTime());
    }

    @Override
    public void submitForInspectAgain(SubmitForFacilities submitForFacilities) {
        // 更新最后一次提交
        submissionmapper.updateStatusWaitByTaskIdAndType(submitForFacilities.getTaskId(),ConstantConfig.INSPECT_SubTASK,ConstantConfig.DROP);
        submitForInspect(submitForFacilities);
    }

    @Override
    public void submitForSample(SubmitForSample submitForSample) {
        // 1.新建一个submission
        Submission submission = new Submission();
        submission.setTaskId(submitForSample.getTaskId());
        SubtaskSample subtaskSample = subtaskSampleMapper.getSubtaskSampleByTaskId(submitForSample.getTaskId());
        submission.setSubtaskId(subtaskSample.getId());
        submission.setReviewStatus(ConstantConfig.WAITING);
        String nowTime = TimeConfig.getNowTime();
        submission.setSubmissionTime(nowTime);
        submission.setType(ConstantConfig.SAMPLE_SubTASK);
        submissionmapper.create(submission);
        // 更新subTaskFacilityComparisonInspect的url和submission_time
        subtaskSampleMapper.updateUrlById(subtaskSample.getId(),submitForSample.getSamplePhotoUrl());
        subtaskSampleMapper.updateTimeById(subtaskSample.getId(),TimeConfig.getNowTime());
    }

    @Override
    public void submitForSampleAgain(SubmitForSample submitForSample) {
        // 更新最后一次提交
        submissionmapper.updateStatusWaitByTaskIdAndType(submitForSample.getTaskId(),ConstantConfig.SAMPLE_SubTASK,ConstantConfig.DROP);
        submitForSample(submitForSample);
    }

    @Override
    public void submitForSimulation(SubmitForSimulation submitForSimulation) {
        // 1.新建一个submission
        Submission submission = new Submission();
        submission.setTaskId(submitForSimulation.getTaskId());
        SubtaskSimulation subtaskSimulation = subTaskSimulationMapper.getSubtaskSimulationByTaskId(submitForSimulation.getTaskId());
        submission.setSubtaskId(subtaskSimulation.getId());
        submission.setReviewStatus(ConstantConfig.WAITING);
        String nowTime = TimeConfig.getNowTime();
        submission.setSubmissionTime(nowTime);
        submission.setType(ConstantConfig.SIMULATION_SubTASK);
        submissionmapper.create(submission);
        // 更新subTaskFacilityComparisonInspect的url和submission_time
        subTaskSimulationMapper.updateUrlById(subtaskSimulation.getId(),submitForSimulation.getReportPdfUrl(),submitForSimulation.getOriginalRecordPdfUrl());
        subTaskSimulationMapper.updateTimeById(subtaskSimulation.getId(),TimeConfig.getNowTime());
    }

    @Override
    public void submitForSimulationAgain(SubmitForSimulation submitForSimulation) {
        // 更新最后一次提交
        submissionmapper.updateStatusWaitByTaskIdAndType(submitForSimulation.getTaskId(),ConstantConfig.SIMULATION_SubTASK,ConstantConfig.DROP);
        submitForSimulation(submitForSimulation);
    }

    @Override
    public void submitForExtra(SubmitForExtra submitForExtra) {
        // 1.新建一个submission
        Submission submission = new Submission();
        submission.setTaskId(submitForExtra.getTaskId());
        SubtaskAdditionalRequirement subtaskAdditionalRequirement = subtaskAdditionalRequirementMapper
                .getSubtaskAdditionalRequirementById(submitForExtra.getSubtaskId());
        submission.setSubtaskId(subtaskAdditionalRequirement.getId());
        submission.setReviewStatus(ConstantConfig.WAITING);
        String nowTime = TimeConfig.getNowTime();
        submission.setSubmissionTime(nowTime);
        submission.setType(ConstantConfig.ADDITIONAL_SubTASK);
        submissionmapper.create(submission);
        // 更新subTaskFacilityComparisonInspect的url和submission_time
        subtaskAdditionalRequirementMapper.updateUrlById(subtaskAdditionalRequirement.getId(),
                submitForExtra.getAttachmentPdfUrl());
        subtaskAdditionalRequirementMapper.updateTimeById(subtaskAdditionalRequirement.getId()
                ,TimeConfig.getNowTime());
    }

    @Override
    public void submitForExtraAgain(SubmitForExtra submitForExtra) {
        // 更新最后一次提交
        submissionmapper.updateStatusWaitByTaskIdAndType(submitForExtra.getTaskId(),ConstantConfig.ADDITIONAL_SubTASK,ConstantConfig.DROP);
        submitForExtra(submitForExtra);
    }

    @Override
    public void readSubmission(int submissionId) {
        submissionmapper.updateStatusById(submissionId,ConstantConfig.DROP);
    }


    @Autowired
    SmallProjectMapper smallProjectMapper;
    @Autowired
    TaskMapper taskMapper;
    @Autowired
    SubtaskStaffMapper subtaskStaffMapper;
    @Autowired
    UserMapper userMapper;
    @Autowired
    SubtaskEquipmentMapper subtaskEquipmentMapper;
    @Autowired
    EquipmentMapper equipmentMapper;
    @Autowired
    SubtaskSampleMapper subtaskSampleMapper;
    @Autowired
    SubtaskFacilityComparisonInspectMapper subtaskFacilityComparisonInspectMapper;
    @Autowired
    SubtaskAdditionalRequirementMapper subtaskAdditionalRequirementMapper;
    @Autowired
    SubTaskSimulationMapper subTaskSimulationMapper;
    @Autowired
    SubmissionMapper submissionmapper;
    @Autowired
    ProjectMapper projectMapper;
    @Autowired
    StandardMapper standardMapper;

}
